from random import random

from khl.card import Card, CardMessage, Module, Types, Element, Struct
import func
from khl import Bot, Message
import os

from keep_alive import keep_alive

# init Bot

my_token = os.getenv('KOOK1_TOKEN')
if my_token is None:
  assert False
bot = Bot(token=my_token)


# # register command
# # invoke this via saying `/hello` in channel
@bot.command(name='hello')
async def world(
    msg: Message,
    a=-1):  # when `name` is not set, the function name will be used
  await msg.reply('world!' + str(a))


@bot.command('help')
async def teach(msg: Message):
  s = func.help()
  cm = CardMessage()
  c = Card(Module.Section(s))
  cm.append(c)
  await msg.reply(cm)


@bot.command('q')
async def ask(msg: Message, a, b, c, d, e, f,
              g):  # when `name` is not set, the function name will be used
  try:
    cm = CardMessage()
    now_info, all_team_info = func.work(a, b, c, d, e, f, g)
    team1_info, team2_info = all_team_info
    c = Card()  # 空卡片消息
    c.append(Module.Header(now_info))
    c.append(Module.Divider())
    for i, it in enumerate(team1_info):
      if i == 0:
        c.append(Module.Header('下一场你是 ' + func.side_eng_to_cn[it] + ' 阵营'))
        continue
      c.append(Module.Section(it))

    c.append(Module.Divider())
    for i, it in enumerate(team2_info):
      if i == 0:
        c.append(Module.Header('下一场对面是 ' + func.side_eng_to_cn[it] + ' 阵营'))
        continue
      c.append(Module.Section(it))

    cm.append(c)
    await msg.reply(cm)
  except Exception as e:
    await msg.reply('有可能格式有问题，也有可能阵营等信息输错了')

  # await msg.reply('wtf')


keep_alive()
# everything done, go ahead now!
bot.run()
